#include "DXUT.h"
#include "StatusEffects.h"

Status::Status(float timeLeft, int strength) {
	fTimeLeft = timeLeft;
	iStrength = strength;
};

Status& Status::operator += (const float& rhs)
{
	fTimeLeft += rhs;
	return *this;
};

Status& Status::operator -= (const float& rhs)
{
	fTimeLeft -= rhs;
	return *this;
};

bool Status::aktiv() {
	return (fTimeLeft > 0.0f);
};

float Damage::cdmg(float dmg, float armorcoef, int armor, UINT type) {
	if (type & UNDEFINED)
		return dmg;
	else
		if (type & PENETRATING)
			return dmg * armorcoef / (armorcoef + static_cast<float>(armor) / 2.0f);
		else
			return dmg * armorcoef / (armorcoef + static_cast<float>(armor));
}

Damage::Damage(UINT type, float value) {
	iType  = type;
	iValue = value;
};

Damage& Damage::operator /= (const Armor& rhs)
{
	if (iType & PHYSICAL)
		iValue = cdmg(iValue, 100.0f, rhs.iPhysical, iType);
	if (iType & FIRE)
		iValue = cdmg(iValue, 50.0f, rhs.iFire, iType);
	if (iType & FROST)
		iValue = cdmg(iValue, 50.0f, rhs.iFrost, iType);
	if (iType & ELECTRO)
		iValue = cdmg(iValue, 50.0f, rhs.iElectro, iType);
	if (iType & NATURE)
		iValue = cdmg(iValue, 50.0f, rhs.iNature, iType);
	if (iType & BLAST)
		iValue = cdmg(iValue, 200.0f, rhs.iPhysical + 2 * rhs.iFire, iType);
	return *this;
};

bool Damage::clearReg() {
	return (iType & HIT) == HIT;
}

Armor::Armor() {
	iPhysical	= 0;
	iFire		= 0;
	iFrost		= 0;
	iElectro	= 0;
	iNature		= 0;
};